from app.models.order import Order
from app.services.retry import retry
import json
import time

class DryRun:
    _orders = {}
    _id = 1

    def save(self, order: Order) -> Order:
        if order.id is None:
            order.id = DryRun._id
            DryRun._id += 1
        self._orders[order.id] = order
        return order

    def get(self, oid: int) -> Order:
        return self._orders[oid]

    @retry(times=5, delay=1)
    def execute(self, code: str, side: str, price: float, qty: int):
        print(f"[DRY-RUN] {side} {qty}@{price}  {code}")

    def status(self, oid: int, st: str):
        self._orders[oid].status = st
        print(f"[DRY-RUN] Order-{oid}  status={st}")

# 模块级单例
dry_run = DryRun()
